#pragma once
#include "../../src_baseClasses/Data.h"
#include "../../src_baseClasses/DiagramData.h"
#include "../../src_baseClasses/dataStructUI.h"
#include "Style_lines.h"

class Data_lines : public Data, public DiagramData {
public:
	Data_lines() { setupStyleManager(); }
	~Data_lines() {}
	//定义绘图样式
	Style_lines m_styleInfo = Style_lines();

	//算法数据
	std::vector<std::vector<LineUI>> m_wires;						//折线集合
	std::vector<std::vector<std::vector<LineUI>>> m_polygonss;		//多层多边形群
	std::vector<LineUI> m_flyLines;

	std::vector<std::vector<LineUI>> fixLines_;
	std::vector<std::vector<LineUI>> lockLines_;
	std::vector<std::vector<double>> diffGaps_;
	std::vector<std::vector<double>> spaces_;
	double miter = 1;
	std::vector<std::vector<double>> obssMinMaxXY;	//障碍物外包盒
	std::vector<int> diffInfo_dirs;              //0(false)表示另一根线在右边，1(true)表示另一根线在左边，2表示非差分线（以左下角为原点，右边为x正方向，上面为y正方向）

	void clear() {
		//1.父类中的数据
		Data::clear();
		//4.算法数据
		m_wires.clear();
		m_polygonss.clear();
		fixLines_.clear();
		lockLines_.clear();
		diffGaps_.clear();
		spaces_.clear();
		miter = 1;
		obssMinMaxXY.clear();
		diffInfo_dirs.clear();
	}

	// 实现DiagramData接口
	QPointF* getMinPoint() override { return &minPt; }
	QPointF* getMaxPoint() override { return &maxPt; }


	// 1.设置背景信息(优先绘制的内容)
	void set_canvas_info_back(
		std::vector<std::vector<QPointF>*>& pts1, std::vector<PointStyle*>& ss_pts1,
		std::vector<std::vector<LineUI>*>& lines1, std::vector<LineStyle*>& ss_lines1,
		std::vector<std::vector<LineUI>*>& polys1, std::vector<PolygonStyle*>& ss_polys1,
		std::vector<std::vector<LineUI>*>& linePts1, std::vector<PointStyle*>& ss_linePts1,
		std::vector<std::vector<CircleUI>*>& circle1, std::vector<PolygonStyle*>& ss_circle1
	) {
		//1.1 点：障碍物
		//1.2 点：规划点
		//1.3 点：预布线点
		//2.1 线：
		//3.1 多边形：
		size_t polygonSum = m_polygonss.size();
		for (size_t i = 0; i < polygonSum; i++) {
			size_t lineSum = m_polygonss[i].size();
			for (size_t j = 0; j < lineSum; j++) {
				polys1.emplace_back(&m_polygonss[i][j]);
			}
			ss_polys1.reserve(ss_polys1.size() + lineSum);
			const auto& style2 = m_styles.getPolygonStyle(m_styleInfo.obsPolyKey);
			std::fill_n(std::back_inserter(ss_polys1), lineSum, style2);
		}
		//4.1 线段端点：
	};
	// 2.设置前景绘图信息(后绘制的内容，会将先绘制的内容挡住)
	void set_canvas_info_front(
		std::vector<std::vector<QPointF>*>& pts2, std::vector<PointStyle*>& ss_pts2,
		std::vector<std::vector<LineUI>*>& lines2, std::vector<LineStyle*>& ss_lines2,
		std::vector<std::vector<LineUI>*>& polys2, std::vector<PolygonStyle*>& ss_polys2,
		std::vector<std::vector<LineUI>*>& linePts2, std::vector<PointStyle*>& ss_linePts2,
		std::vector<std::vector<CircleUI>*>& circle2, std::vector<PolygonStyle*>& ss_circle2
	) {
		//1.1 点：
		//2.1 线：飞线
		lines2.emplace_back(&m_flyLines);
		ss_lines2.emplace_back(m_styles.getLineStyle(m_styleInfo.flyLineKey));
		//2.2 线：走线
		size_t lineSum = m_wires.size();
		for (size_t i = 0; i < lineSum; i++)
			lines2.emplace_back(&m_wires[i]);
		ss_lines2.reserve(ss_lines2.size() + lineSum);
		const auto& style2 = m_styles.getLineStyle(m_styleInfo.pathLineKey);
		std::fill_n(std::back_inserter(ss_lines2), lineSum, style2);
		//3.1 多边形：
		//4.1 线段端点：
		
	};

private:
	void setupStyleManager() {
		m_styles.setPointStyle(m_styleInfo.pointStyleKeys, m_styleInfo.pointStyles);
		m_styles.setLineStyle(m_styleInfo.lineStyleKeys, m_styleInfo.lineStyles);
		m_styles.setPolygonStyle(m_styleInfo.polygonStyleKeys, m_styleInfo.polygonStyles);
	}
};

